package com.spider.spiderorderbasedata.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.spider.spiderorderbasedata.mapper.DataLocationMapper;
import com.spider.spiderorderbasedata.model.entity.DataLocation;
import com.spider.spiderorderbasedata.service.DataLocationService;
import org.springframework.stereotype.Service;

/**
 * @author xiong.bo
 * @version 1.0
 * @date 2024/5/10 8:19 下午
 */

@Service
public class DataLocationServiceImpl extends ServiceImpl<DataLocationMapper, DataLocation>
        implements DataLocationService {

    @Override
    public IPage<DataLocation> selectPage(int page, int pageSize) {
        Page<DataLocation> pageObject = new Page(page, pageSize);
        LambdaQueryWrapper<DataLocation> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.orderByDesc(DataLocation::getCreateTime);
        return this.baseMapper.selectPage(pageObject, queryWrapper);
    }

    @Override
    public DataLocation findById(Long id) {
        return this.getById(id);
    }

    @Override
    public DataLocation saveLocation(DataLocation dataLocation) {
        this.save(dataLocation);
        return dataLocation;
    }

    @Override
    public DataLocation editLocation(DataLocation dataLocation) {
        this.updateById(dataLocation);
        return dataLocation;
    }

    @Override
    public Boolean deleteLocation(Long id) {
        return this.removeById(id);
    }
}
